package com.example.springcloudeurekaserverproducer.mybatis.interceptor.dialect;

import org.springframework.util.Assert;



/**
 * Oracle 数据库分页语句组装实现
 * @ClassName: OracleDialect
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @author lanyuansong
 * @date 2018年7月11日
 */
public class OracleDialect implements IDialect {

    @Override
    public String buildPaginationSql(String sql, int pageNow, int pageSize) {
    	StringBuffer sb = new StringBuffer();
		Assert.notNull(sql, sql + "不能为空!");
		sb.append("SELECT *").append(" FROM (SELECT a.*, ROWNUM rn ").append("FROM ("+sql +") a ");
		sb.append("WHERE ROWNUM <= "+pageNow*pageSize+") ");
		sb.append("WHERE rn >= "+((pageNow -1)*pageSize+1)+" ");
		return sb.toString();
        
    }
    
    public static void main(String[] args) {
		String sql = "select * FROM BU_EWALLET_TTLV WHERE TAC_CHECK='UC99'";
		System.out.println(new OracleDialect().buildPaginationSql(sql, 0, 100));
	}

}
